<?php
	//修改个人资料
	require '../biz/backend.php';

	class action extends backend
	{
		var $get_privilege_id = '80';
		var $post_privilege_id = '80';

		function do_get()
		{
			$mood = '';

			$account = load( 'biz.account' );
			$template = load( 'template', array( 'domain'=>'tpl.admin' ) );
			$data = $account->detail();

			$template->appoint( $data );
			$template->assign( 'reference', isset( $this->input['reference'] ) ? urldecode( $this->input['reference'] ) : config( 'domain.admin' ) . 'entrance.php' );
			echo $template->parse( 'set_info.php' );
		}

		function do_post()
		{
			$this->input['city'] = $this->input['province'] . ' ' . $this->input['city'];

			$url = isset( $this->input['reference'] ) ? $this->input['reference'] : config( 'domain.admin' ) . 'set_config.php';
			unset( $this->input['reference'], $this->input['province'] );

			$account = load( 'biz.account' );

			$result = $account->set_baseinfo( $this->input );
			$headerimg = $account->modify_logo( 'logo', $this->account_info['user_id'] );
			if ( $headerimg != '' ) $account->database->command( "update account set headerimg = '" . $headerimg . "' where id = " . $this->account_info['id'] );

			if ( isset( $this->input['mood'] ) && $this->input['mood'] != '' )
			{
				$database = load( 'database' );
				$temp = $database->unique( 'select id from account where user_id = ' . $this->account_info['user_id'] );
				if ( isset( $temp['id'] ) ) $database->command( "update actor set mood = '" . $this->input['mood'] . "' where account_id = " . $temp['id'] );
			}

			if ( $result == '0' )
			{
				$this->prompt( '成功修改资料', array( array( 'url' => config( 'domain.admin' ) . 'entrance.php', 'name' => '返回首页' ), array( 'url' => config( 'domain.admin' ) . 'set_info.php?reference=' . urlencode( $url ), 'name' => '重新修改资料' ) ) );
			}
			else
			{
				$this->prompt( '修改资料失败[' . $result . ']', array( array( 'url' => config( 'server.HTTP_REFERER' ), 'name' => '重新修改资料' ) ) );
			}
		}
	}

	$action = new action();
	$action->run();
?>